const babel = require('@babel/core');

const code = `<h1>
hello<span style={{ color: 'red' }}>world</span>
</h1>`;

const result = babel.transformSync(code, {
  plugins: [
    [
      '@babel/plugin-transform-react-jsx',
      {
        runtime: 'automatic',
      },
    ],
  ],
});

// 不再需要引入 react
/*
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
_jsxs("h1", {
  children: ["hello", _jsx("span", {
    style: {
      color: 'red'
    },
    children: "world"
  })]
})
*/

console.log(result.code);
